<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <title>项目切换</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
<div class="box box-primary" id="more" style="width:110px;height:20px;background-color:#222c32;position:absolute;z-index:9999;left:850px;top:100px;display:none;font-size:12px;border-top-color:#222c32;">
            <!-- <div class="box-header with-border">
                	更多操作
            </div> --><!-- /.box-header -->
            <div class="box-body home-message" id="moreOp">
            </div>
        </div>
    <section class="content-header">
        <h1>项目切换</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active">招标采购管理</li>
            <li class="active">项目切换</li>
        </ol>
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class=" form-inline">
                	<div class="form-group form-group-xs">
                	    <label for="txtDrugName">名称：</label>
					    <select class="form-control" style="width:220px;" id="projId" name="projId"></select>
                	</div>
                    <div class="form-group form-group-xs">
                        <label for="txtDrugForm">状态：</label>
                        <select class="form-control"  id="status" name="status">
                        	<option value="">请选择</option>
                        	<option value="1">启用</option>
                        	<option value="0">停用</option>
                        </select>
                    </div>
                    <button type="button" onclick="gridSerch()" class="btn btn-success btn-sm">查&nbsp;询</button>
                </div>
            </div>
        </div>

        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>

        <div class=" box box-warning bottongroup">
        <button  class="btn btn-default btn-sm"  onclick="reSet()">重&nbsp;置</button>
        </div>
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp" %>
    <script type="text/javascript">
        $(function () {
            $("#gridlist").jqGrid({
                url: "${ctx}/bidProject/getChangeBidProjectList.html",
                mtype: "POST",
                datatype: "json",
                autowidth: true,
                shrinkToFit:true,
                height: 270,
                colNames: [ '操作','projId','项目名称','采购开始日期','采购结束日期', '状态','是否默认'],
                colModel: [
                    { name: 'defaultProjId', width:80,sortable: false, align:"center",
                    	formatter : function(val, opts, rowdata) {
                    		var str = "";
                    		if (val!=null &&val!="" ) {//已设置默认值
                    			str += ""; 
                    		}else{
                    			str += "<a href='javascript:setDefaultProj(\""+rowdata.projId+"\",\""+rowdata.name+"\");' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -60px -20px' class='opIcon' title='设为默认'></a>";   
                    		}
                    		return str;
                    	}	
                    },
                    { name: 'projId', key:true,hidden:true,width: 0, align: 'center' ,sortable: false},
                    { name: 'name', width: 200, align: 'left' ,sortable: false},
                    { name: 'starttime', width:100, align: 'center' ,sortable: false,
                    	formatter :  function(val, opts,rowdata) {
                	    	return new Date(val).format("yyyy-MM-dd");
                		}
                    },
                    { name: 'endtime', width: 100, align: 'center' ,sortable: false,
                        formatter :  function(val, opts,rowdata) {
                	    	return new Date(val).format("yyyy-MM-dd");
                		} 
                    },
                    { name : 'status', width : 80, align : 'center', sortable : false,
							formatter : function(val, opts,rowdata) {
						    	if (val == 1) {
									return "启用";
							} else if (val == 0) {
									return "停用";
							}
					}},
					 { name: 'defaultProjId', width:80,sortable: false, align:"center",
                    	formatter : function(val, opts, rowdata) {
                    		var str = "";
                    		if (val!=null &&val!="" ) {//已设置默认值 
                    			str += "<span style='color:red'>是</span>"; 
                    		}else{
                    			str += "否";   
                    		}
                    		return str;
                    	}	
                    }
                 
                ],
                rowNum: 0,
                rownumbers: true,
                viewrecords: true,
                multiselect: false, 
                caption: "项目列表",
                //序号宽度自动变化
                gridComplete:function(){
                   
                },
                jsonReader: {
                    repeatitems: false  
                },
                loadComplete: function (data) {
                	formatSelect("#projId",data.rows);
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
        });
        //设置默认
        function setDefaultProj(projId,projName){
        	$.HN.message.confirm("确定将<span style='color:red'>"+projName+"</span>设置为默认项目吗？", '', '').on(function (e) {
	            if (e) {
	            	$.post("${ctx}/bidProject/toSetDefaultProj.html",{"projId":projId},function(result){
	            		if(result.success){
	            			  $.HN.message.alert('操作成功！', '提示信息', 'success');
	        			      top.changeBidProject(projName);   
	        			      $("#gridlist").trigger("reloadGrid");
	            		}
	            	},"json");
	          	} 
	  	  });
        }
        
        //重置
        function reSet(projName){
          	$.HN.message.confirm("确定<span style='color:red'>重置</span>全部项目吗？", '', '').on(function (e) {
	            if (e) {
	            	$.post("${ctx}/bidProject/toReSetDefaultProj.html","",function(result){
	            		if(result.success){
        			        $.HN.message.alert('操作成功！', '提示信息', 'success');
        			        top.changeBidProject("<i class='fa fa-circle text-success'></i>在线");
        			        $("#gridlist").trigger("reloadGrid");
	            		}
	            	},"json");
	          	  } 
	  	  });
        }
        
        //查询
        function gridSerch() {
        	var status = $("#status").val();
        	var projId = $("#projId").val();
    		$("#gridlist").jqGrid('setGridParam',{  
    	        datatype:'json',
    	        postData:{
    	        		"projId":projId,
    	        		"status":status
    	        }
    	    }).trigger("reloadGrid"); //重新载入  
    	}
    </script>
</body>
</html>